import 'package:flutter/material.dart';

class RadioPage extends StatefulWidget {
  @override
  _RadioPageState createState() => new _RadioPageState();
}

class _RadioPageState extends State<RadioPage> {
  @override
  Widget build(BuildContext context) {
    final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey();

    return Scaffold(
      key: _scaffoldKey,
      appBar: AppBar(
        title: Text("Radio"),
      ),
      body: _buildListView(),
    );
  }

  Widget _buildListView() {
    return ListView.builder(
      itemBuilder: (context, index) {
        return _buildListViewItem(index);
      },
      itemCount: radios.length,
    );
  }

  Widget _buildListViewItem(index) {
    return Container(
      padding: EdgeInsets.all(10.0),
      alignment: Alignment.center,
      child: radios[index],
    );
  }
}

String _radioValue = '1';
String _radioGroupValue = '';

List<Widget> radios = <Widget>[
  Column(
    children: <Widget>[
      Text("Radio"),
      Container(
        child: Radio(
          value: _radioValue,
          groupValue: _radioGroupValue,
          onChanged: (value) {},
        ),
      ),
    ],
  ),
  Column(
    children: <Widget>[
      Text("RadioListTile"),
      Container(
        child: Row(
          children: <Widget>[
            Radio(
              value: '语文',
              groupValue: _radioGroupValue,
              onChanged: (value) {},
            ),
            Radio(
              value: '数学',
              groupValue: _radioGroupValue,
              onChanged: (value) {},
            ),
            Radio(
              value: '英语',
              groupValue: _radioGroupValue,
              onChanged: (value) {},
            ),
          ],
        ),
      ),
    ],
  ),
  Column(
    children: <Widget>[
      Text("Radio"),
      Container(
        child: Row(
          children: <Widget>[
            Flexible(
              child: RadioListTile(
                title: Text('语文'),
                value: '语文',
                groupValue: _radioGroupValue,
                onChanged: (value) {},
              ),
            ),
            Flexible(
                child: RadioListTile(
              title: Text('数学'),
              value: '数学',
              groupValue: _radioGroupValue,
              onChanged: (value) {},
            )),
            Flexible(
                child: RadioListTile(
              title: Text('英语'),
              value: '英语',
              groupValue: _radioGroupValue,
              onChanged: (value) {},
            )),
          ],
        ),
      ),
    ],
  ),
];
